package com.framework.model.system;

import com.framework.common.annotation.QueryParam;
import com.framework.common.model.validation.ValidationGroup;
import com.framework.common.util.match.MatchConstantUtil;
import com.framework.common.util.other.NumeralUtil;
import com.framework.model.base.BaseModel;

import javax.validation.constraints.Email;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import java.io.Serializable;

/**
 * @author 龘鵺
 * @version 1.0
 * @className com.framework.model.system.SystemUser
 * @title 用户管理类
 * @datetime 2024-06-19 09:34:28
 */
public class SystemUser extends BaseModel implements Serializable {
    /**
     * 启用状态（1启用,2禁用） ENABLE_STATUS
     */
    @NotNull(message = "请选择启用状态", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
    @Min(message = "启用状态错误", value = NumeralUtil.POSITIVE_ONE, groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
    @Max(message = "启用状态错误", value = Integer.MAX_VALUE, groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
    @QueryParam(name = "enableStatus", code = "p.ENABLE_STATUS")
    private Integer enableStatus;

    /**
     * 帐号 ACCOUNT
     */
    @NotBlank(message = "{user.username.notBlank}", groups = {ValidationGroup.formAdd.class})
    @Size(message = "{user.username.size}", min = NumeralUtil.POSITIVE_SIX, max = NumeralUtil.POSITIVE_TWENTY_FIVE, groups = {ValidationGroup.formAdd.class})
    @QueryParam(name = "account", code = "p.ACCOUNT")
    private String account;

    /**
     * 密码 PASSWORD
     */
    @NotBlank(message = "请输入密码", groups = {ValidationGroup.formAdd.class, ValidationGroup.formPassword.class})
//    @Size(message = "密码最少6至最多25个字符", min = NumeralUtil.POSITIVE_SIX, max = NumeralUtil.POSITIVE_TWENTY_FIVE,  groups = {ValidationGroup.formAdd.class, ValidationGroup.formPassword.class})
    @QueryParam(name = "password", code = "p.PASSWORD")
    private String password;

    /**
     * 姓名 NAME
     */
    @NotBlank(message = "请输入姓名", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class})
    @Size(message = "姓名最多20个字符", max = NumeralUtil.POSITIVE_TWENTY, groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class, ValidationGroup.formQuery.class})
    @QueryParam(name = "name", code = "p.NAME")
    private String name;

    /**
     * 电话 PHONE
     */
    @NotBlank(message = "请输入电话", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class})
    @Pattern(regexp = MatchConstantUtil.REGEX_PHONE, message = "请输入正确电话号码!", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class})
    @QueryParam(name = "phone", code = "p.PHONE")
    private String phone;

    /**
     * 邮箱 EMAIL
     */
    @Email(message = "请输入正确邮箱", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class})
    @NotBlank(message = "请输入邮箱", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class})
    @Size(message = "邮箱最多64个字符", max = NumeralUtil.POSITIVE_SIXTY_FOUR, groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class, ValidationGroup.formOther.class, ValidationGroup.formQuery.class})
    @QueryParam(name = "email", code = "p.EMAIL")
    private String email;

    /**
     * 帐号层级, 顶级为0.根据当前帐号的等级+1进行级别控制 USER_LEVEL
     */
    @NotNull(message = "请输入帐号级别", groups = {ValidationGroup.formEdit.class})
    @Min(message = "帐号级别错误", value = NumeralUtil.NEGATIVE_ONE, groups = {ValidationGroup.formEdit.class})
    @Max(message = "帐号级别错误", value = Integer.MAX_VALUE, groups = {ValidationGroup.formEdit.class})
    @QueryParam(name = "userLevel", code = "p.USER_LEVEL")
    private Integer userLevel;

    /**
     * 描述 DESCRIPTION
     */
//    @NotBlank(message = "请输入描述", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
    @Size(message = "描述最多1000个字符", max = NumeralUtil.POSITIVE_ONE_THOUSAND, groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
    @QueryParam(name = "description", code = "p.DESCRIPTION")
    private String description;

    /**
     * 盐 SALT
     */
//    @NotBlank(message = "请输入盐", groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
//    @Size(message = "盐最多32字符", max = 32, groups = {ValidationGroup.formEdit.class, ValidationGroup.formAdd.class})
    @QueryParam(name = "salt", code = "p.SALT")
    private String salt;

    /**
     * system_user
     */
    private static final long serialVersionUID = 1L;

    public Integer getEnableStatus() {
        return enableStatus;
    }

    public void setEnableStatus(Integer enableStatus) {
        this.enableStatus = enableStatus;
    }

    public String getAccount() {
        return account;
    }

    public void setAccount(String account) {
        this.account = account == null ? null : account.trim();
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password == null ? null : password.trim();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone == null ? null : phone.trim();
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email == null ? null : email.trim();
    }

    public Integer getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(Integer userLevel) {
        this.userLevel = userLevel;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description == null ? null : description.trim();
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt == null ? null : salt.trim();
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", enableStatus=").append(enableStatus);
        sb.append(", account=").append(account);
        sb.append(", password=").append(password);
        sb.append(", name=").append(name);
        sb.append(", phone=").append(phone);
        sb.append(", email=").append(email);
        sb.append(", userLevel=").append(userLevel);
        sb.append(", description=").append(description);
        sb.append(", salt=").append(salt);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        SystemUser other = (SystemUser) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getCreateId() == null ? other.getCreateId() == null : this.getCreateId().equals(other.getCreateId()))
                && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
                && (this.getOperaterId() == null ? other.getOperaterId() == null : this.getOperaterId().equals(other.getOperaterId()))
                && (this.getOperaterTime() == null ? other.getOperaterTime() == null : this.getOperaterTime().equals(other.getOperaterTime()))
                && (this.getOperaterStatus() == null ? other.getOperaterStatus() == null : this.getOperaterStatus().equals(other.getOperaterStatus()))
                && (this.getEnableStatus() == null ? other.getEnableStatus() == null : this.getEnableStatus().equals(other.getEnableStatus()))
                && (this.getAccount() == null ? other.getAccount() == null : this.getAccount().equals(other.getAccount()))
                && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
                && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
                && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
                && (this.getEmail() == null ? other.getEmail() == null : this.getEmail().equals(other.getEmail()))
                && (this.getUserLevel() == null ? other.getUserLevel() == null : this.getUserLevel().equals(other.getUserLevel()))
                && (this.getDescription() == null ? other.getDescription() == null : this.getDescription().equals(other.getDescription()))
                && (this.getSalt() == null ? other.getSalt() == null : this.getSalt().equals(other.getSalt()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getCreateId() == null) ? 0 : getCreateId().hashCode());
        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
        result = prime * result + ((getOperaterId() == null) ? 0 : getOperaterId().hashCode());
        result = prime * result + ((getOperaterTime() == null) ? 0 : getOperaterTime().hashCode());
        result = prime * result + ((getOperaterStatus() == null) ? 0 : getOperaterStatus().hashCode());
        result = prime * result + ((getEnableStatus() == null) ? 0 : getEnableStatus().hashCode());
        result = prime * result + ((getAccount() == null) ? 0 : getAccount().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
        result = prime * result + ((getEmail() == null) ? 0 : getEmail().hashCode());
        result = prime * result + ((getUserLevel() == null) ? 0 : getUserLevel().hashCode());
        result = prime * result + ((getDescription() == null) ? 0 : getDescription().hashCode());
        result = prime * result + ((getSalt() == null) ? 0 : getSalt().hashCode());
        return result;
    }
}